package com.ruoyi.slope.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.ai.domain.SlopeAiMonitoringMissionConfig;
import com.ruoyi.slope.ai.service.ISlopeAiMonitoringMissionConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监测任务配置Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/taskConfig")
public class SlopeAiMonitoringMissionConfigController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiMonitoringMissionConfigService slopeAiMonitoringMissionConfigService;

    /**
     * 查询监测任务配置列表
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiMonitoringMissionConfig slopeAiMonitoringMissionConfig)
    {
        startPage();
        List<SlopeAiMonitoringMissionConfig> list = slopeAiMonitoringMissionConfigService.selectSlopeAiMonitoringMissionConfigList(slopeAiMonitoringMissionConfig);
        return getDataTable(list);
    }

    /**
     * 导出监测任务配置列表
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:export')")
    @Log(title = "监测任务配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiMonitoringMissionConfig slopeAiMonitoringMissionConfig)
    {
        List<SlopeAiMonitoringMissionConfig> list = slopeAiMonitoringMissionConfigService.selectSlopeAiMonitoringMissionConfigList(slopeAiMonitoringMissionConfig);
        ExcelUtil<SlopeAiMonitoringMissionConfig> util = new ExcelUtil<SlopeAiMonitoringMissionConfig>(SlopeAiMonitoringMissionConfig.class);
        String path = util.exportExcel(response, list, "监测任务配置数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取监测任务配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:query')")
    @GetMapping(value = "/{missionId}")
    public AjaxResult getInfo(@PathVariable("missionId") String missionId)
    {
        return success(slopeAiMonitoringMissionConfigService.selectSlopeAiMonitoringMissionConfigByMissionId(missionId));
    }

    /**
     * 新增监测任务配置
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:add')")
    @Log(title = "监测任务配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiMonitoringMissionConfig slopeAiMonitoringMissionConfig)
    {
        return toAjax(slopeAiMonitoringMissionConfigService.insertSlopeAiMonitoringMissionConfig(slopeAiMonitoringMissionConfig));
    }

    /**
     * 修改监测任务配置
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:edit')")
    @Log(title = "监测任务配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiMonitoringMissionConfig slopeAiMonitoringMissionConfig)
    {
        return toAjax(slopeAiMonitoringMissionConfigService.updateSlopeAiMonitoringMissionConfig(slopeAiMonitoringMissionConfig));
    }

    /**
     * 删除监测任务配置
     */
    @PreAuthorize("@ss.hasPermi('ai:taskConfig:remove')")
    @Log(title = "监测任务配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{missionIds}")
    public AjaxResult remove(@PathVariable String[] missionIds)
    {
        return toAjax(slopeAiMonitoringMissionConfigService.deleteSlopeAiMonitoringMissionConfigByMissionIds(missionIds));
    }
}
